package com.voilet.interview.android.aidl;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;

import com.base.interview.app.BaseActivity;

/**
 * Created by kan212 on 2019/4/2.
 */

public class TestAidlActivity extends BaseActivity {

    AdditionService additionService;
    AdditionServiceConn conn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initService();
    }

    private void initService() {
        conn = new AdditionServiceConn();
        Intent intent = new Intent();
        intent.setClassName("com.voilet.interview.android.aidl",com.voilet.interview.android.aidl.IAdditionService.class.getName());
        bindService(intent,conn, Context.BIND_AUTO_CREATE);
    }

    class AdditionServiceConn implements ServiceConnection {

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            additionService = (AdditionService) IAdditionService.Stub.asInterface(service);
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            additionService = null;
        }
    }
}
